<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <!-- <el-form-item label="审核编号" prop="ethicalReviewNumber">
        <el-input
          v-model="queryParams.ethicalReviewNumber"
          placeholder="请输入审核编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="待审核新实验ID" prop="newExperimentId">
        <el-input
          v-model="queryParams.newExperimentId"
          placeholder="请输入待审核新实验ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="待审核新实验名称" prop="ethicalReviewBy2">
        <el-input
          v-model="queryParams.ethicalReviewBy2"
          placeholder="请输入待审核新实验名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="审核状态" prop="typeId">
        <el-input
          v-model="queryParams.typeId"
          placeholder="请输入审核状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="审核状态" prop="ethicalReviewBy3">
         <el-select v-model="queryParams.ethicalReviewBy3" placeholder="请选择" @keyup.enter.native="handleQuery">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
        <!-- <el-input
          v-model="queryParams.ethicalReviewBy3"
          placeholder="请输入审核状态"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
      </el-form-item>
      <!-- <el-form-item label="审核时间" prop="ethicalReviewDate">
        <el-date-picker clearable
          v-model="queryParams.ethicalReviewDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择审核时间">
        </el-date-picker>
      </el-form-item> -->
      <el-form-item label="审核员工姓名" prop="ethicalReviewBy1">
        <el-input
          v-model="queryParams.ethicalReviewBy1"
          placeholder="请输入审核员工姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="备用列" prop="ethicalReviewBy1">
        <el-input
          v-model="queryParams.ethicalReviewBy1"
          placeholder="请输入备用列"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      -->
<!--       
      <el-form-item label="备用列" prop="ethicalReviewBy2">
        <el-input
          v-model="queryParams.ethicalReviewBy2"
          placeholder="请输入备用列"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      -->
      <!--
      <el-form-item label="备用列" prop="ethicalReviewBy3">
        <el-input
          v-model="queryParams.ethicalReviewBy3"
          placeholder="请输入备用列"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="审核员工ID" prop="staffId">
        <el-input
          v-model="queryParams.staffId"
          placeholder="请输入审核员工ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['review:ethicalReview:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['review:ethicalReview:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['review:ethicalReview:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['review:ethicalReview:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->

    <el-table v-loading="loading" :data="ethicalReviewList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="审核实验编号" align="center" prop="ethicalReviewId"/>
      <!-- <el-table-column label="审核编号" align="center" prop="ethicalReviewNumber" /> -->
      <!-- <el-table-column label="待审核新实验ID" align="center" prop="newExperimentId" /> -->
      <el-table-column label="待审核新实验名称" align="center" prop="ethicalReviewBy2" />
      <el-table-column label="审核状态ID" align="center" prop="typeId"  v-if="false"/>
      <el-table-column label="审核状态" align="center" prop="ethicalReviewBy3" />
      <el-table-column label="审核时间" align="center" prop="ethicalReviewDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ethicalReviewDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="备用列" align="center" prop="ethicalReviewBy1" /> -->
      <!-- <el-table-column label="备用列" align="center" prop="ethicalReviewBy2" /> -->
      <!-- <el-table-column label="备用列" align="center" prop="ethicalReviewBy3" /> -->
      <!-- <el-table-column label="审核员工ID" align="center" prop="staffId" /> -->
      <el-table-column label="审核员工姓名" align="center" prop="ethicalReviewBy1" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['review:ethicalReview:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['review:ethicalReview:remove']"
          >删除</el-button> -->
          <p v-if="scope.row.ethicalReviewBy3=='审核中'">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-check"
              @click="add(scope.row)"
            >审核通过</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-close"
              @click="noAdd(scope.row)"
            >审核不通过</el-button>
          </p>
          <p v-if="scope.row.ethicalReviewBy3=='审核不通过'">
            <el-button disabled
              size="mini"
              type="text"
              icon="el-icon-check"
              @click="add(scope.row)"
            >审核通过</el-button>
            <el-button disabled
              size="mini"
              type="text"
              icon="el-icon-close"
              @click="noAdd(scope.row)"
            >审核不通过</el-button>
          </p>
          <p v-if="scope.row.ethicalReviewBy3=='审核通过'">
            <el-button disabled
              size="mini"
              type="text"
              icon="el-icon-check"
              @click="noAdd(scope.row)"
            >审核通过</el-button>
            <el-button disabled
              size="mini"
              type="text"
              icon="el-icon-close"
              @click="noAdd(scope.row)"
            >审核不通过</el-button>
          </p>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改伦理审核对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!-- <el-form-item label="审核编号" prop="ethicalReviewNumber">
          <el-input v-model="form.ethicalReviewNumber" placeholder="请输入审核编号" />
        </el-form-item> -->
        <!-- <el-form-item label="待审核新实验ID" prop="newExperimentId">
          <el-input v-model="form.newExperimentId" placeholder="请输入待审核新实验ID" />
        </el-form-item> -->
        <el-form-item label="审核状态" prop="typeId">
          <el-input v-model="form.typeId" placeholder="请输入审核状态" />
        </el-form-item>
        <el-form-item label="审核时间" prop="ethicalReviewDate">
          <el-date-picker clearable
            v-model="form.ethicalReviewDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择审核时间">
          </el-date-picker>
        </el-form-item>
        <!-- <el-form-item label="备用列" prop="ethicalReviewBy1">
          <el-input v-model="form.ethicalReviewBy1" placeholder="请输入备用列" />
        </el-form-item>
        <el-form-item label="备用列" prop="ethicalReviewBy2">
          <el-input v-model="form.ethicalReviewBy2" placeholder="请输入备用列" />
        </el-form-item>
        <el-form-item label="备用列" prop="ethicalReviewBy3">
          <el-input v-model="form.ethicalReviewBy3" placeholder="请输入备用列" />
        </el-form-item> -->
        <!-- <el-form-item label="审核员工ID" prop="staffId">
          <el-input v-model="form.staffId" placeholder="请输入审核员工ID" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listEthicalReview, getEthicalReview, delEthicalReview, addEthicalReview, updateEthicalReview ,addE,noAddE} from "@/api/review/ethicalReview";

export default {
  name: "EthicalReview",
  data() {
    return {
      options: [{
          value: '审核中',
          label: '审核中'
        }, {
          value: '审核通过',
          label: '审核通过'
        }, {
          value: '审核不通过',
          label: '审核不通过'
        }],
        value: '',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 伦理审核表格数据
      ethicalReviewList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ethicalReviewNumber: null,
        // newExperimentId: null,
        typeId: null,
        ethicalReviewDate: null,
        ethicalReviewBy1: null,
        ethicalReviewBy2: null,
        ethicalReviewBy3: null,
        // staffId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询伦理审核列表 */
    getList() {
      this.loading = true;
      listEthicalReview(this.queryParams).then(response => {
        this.ethicalReviewList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        ethicalReviewId: null,
        ethicalReviewNumber: null,
        // newExperimentId: null,
        typeId: null,
        ethicalReviewDate: null,
        ethicalReviewBy1: null,
        ethicalReviewBy2: null,
        ethicalReviewBy3: null,
        // staffId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.ethicalReviewId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加伦理审核";
    },
    // /** 修改按钮操作 */
    // handleUpdate(row) {
    //   this.reset();
    //   const ethicalReviewId = row.ethicalReviewId || this.ids
    //   getEthicalReview(ethicalReviewId).then(response => {
    //     this.form = response.data;
    //     this.open = true;
    //     this.title = "修改伦理审核";
    //   });
    // },
    /** 提交按钮 */
    // submitForm() {
    //   this.$refs["form"].validate(valid => {
    //     if (valid) {
    //       if (this.form.ethicalReviewId != null) {
    //         updateEthicalReview(this.form).then(response => {
    //           this.$modal.msgSuccess("修改成功");
    //           this.open = false;
    //           this.getList();
    //         });
    //       } else {
    //         addEthicalReview(this.form).then(response => {
    //           this.$modal.msgSuccess("新增成功");
    //           this.open = false;
    //           this.getList();
    //         });
    //       }
    //     }
    //   });
    // },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ethicalReviewIds = row.ethicalReviewId || this.ids;
      this.$modal.confirm('是否确认删除伦理审核编号为"' + ethicalReviewIds + '"的数据项？').then(function() {
        return delEthicalReview(ethicalReviewIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 审核通过操作 */
    add(row) {
      const ethicalReviewIds = row.ethicalReviewId || this.ids;
      this.$modal.confirm('是否通过该实验"' + ethicalReviewIds + '？').then(function() {
        return addE(ethicalReviewIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("审核通过");
      }).catch(() => {});
    },
    /** 审核不通过操作 */
    noAdd(row) {
      const ethicalReviewIds = row.ethicalReviewId || this.ids;
      this.$modal.confirm('是否拒绝该实验"' + ethicalReviewIds + '？').then(function() {
        return noAddE(ethicalReviewIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("审核不通过");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('review/ethicalReview/export', {
        ...this.queryParams
      }, `ethicalReview_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
